﻿/**********************************弘石项目*******************************************
* 功能描述:考勤 加班 出勤 假日
* 作者:石锦涛
* 时间:2021-12-14
* 
**********************************弘石项目*******************************************/
using HongStone.Domain.OperationsManagement;
using HongStone.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MiniExcelLibs;
using HongStone.Domain.AttendanceManagement;

namespace HongStone.API.Controllers
{
    [ApiExplorerSettings(GroupName = "CheckAttendance")]
    [Route("api/[controller]/[action]")]
    [ApiController]
     public class CheckAttendanceController : ControllerBase
    {
        private readonly CheckAttendanceBll _checkAttendanceBll;
        public CheckAttendanceController(CheckAttendanceBll checkAttendanceBll)
        {
            _checkAttendanceBll = checkAttendanceBll;
        }

        /// <summary>
        /// 部门加班补助显示
        /// </summary>
        /// <param name="nian"></param>
        /// <param name="yue"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult showSubsidy(int? bum, string nian, string yue)
        {
            try
            {

                return Ok(_checkAttendanceBll.showSubsidy(bum, nian, yue));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 部门加班 导出 Excel 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult SubsidyExcel()
        {
            //根据你所选中的方法 写要求  分页如下   无要求为空
            var values = _checkAttendanceBll.showSubsidy(0, null, null);
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(values.ToList());
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "demo.xlsx"
            };
        }



        /// <summary>
        /// 部门显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowOPLa()
        {
            try
            {
                return Ok(_checkAttendanceBll.ShowOPLa());
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 编辑修改补助
        /// </summary>
        /// <param name="subsidy"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateSubsidy(DepartmentSubsidy subsidy)
        {
            try
            {
                return Ok(_checkAttendanceBll.UpdateSubsidy(subsidy));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 部门经理加班补助显示
        /// </summary>
        /// <param name="nian"></param>
        /// <param name="yue"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult showJingliSubsidy(int? bum, string nian, string yue)
        {
            try
            {

                return Ok(_checkAttendanceBll.showJingliSubsidy(bum, nian, yue));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 部门加班 导出 Excel 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult JingliExcel()
        {

            //根据你所选中的方法 写要求  分页如下   无要求为空
            var values = _checkAttendanceBll.showJingliSubsidy(0, null, null);
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(values.ToList());
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "demo.xlsx"
            };
        }

        /// <summary>
        /// 显示添加经理页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult showManager()
        {
            try
            {
                return Ok(_checkAttendanceBll.showManager());
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 查找人员
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pum"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult AddManger(string name, int? pum)
        {
            try
            {
                return Ok(_checkAttendanceBll.AddManger(name, pum));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 承接部门
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Showbumen()
        {
            try
            {
                return Ok(_checkAttendanceBll.Showbumen());
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 添加经理
        /// </summary>
        /// <param name="managerSet"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostAddManger(DepartmentManagerSet managerSet)
        {
            try
            {
                return Ok(_checkAttendanceBll.PostAddManger(managerSet));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 修改总经理
        /// </summary>
        /// <param name="managerZhong"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostZAddManger(DepartmentManagerZhong managerZhong)
        {
            try
            {
                return Ok(_checkAttendanceBll.PostZAddManger(managerZhong));
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 删除经理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Deletjinli(int id)
        {
            try
            {
                return Ok(_checkAttendanceBll.Deletjinli(id));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 删除总经理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Deletzjinli(int id)
        {
            try
            {

                return Ok(_checkAttendanceBll.Deletzjinli(id));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 假日添加
        /// </summary>
        /// <param name="dayOff"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddDayOffA(DayOffTable dayOff)
        {
            try
            {
                return Ok(_checkAttendanceBll.AddDayOffA(dayOff));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 特殊假日添加
        /// </summary>
        /// <param name="dayOff"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddSpecialDayOffB(SpecialDayOffTable specialDay)
        {
            try
            {
                return Ok(_checkAttendanceBll.AddSpecialDayOffB(specialDay));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 假日 显示 查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowDayOffA(int? timee)
        {
            try
            {
                return Ok(_checkAttendanceBll.ShowDayOffA(timee));

            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 特殊假日 显示 查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowSpecialDayOffB(int? times)
        {
            try
            {
                return Ok(_checkAttendanceBll.ShowSpecialDayOffB(times));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 假日 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DateDayOffA(int id)
        {
            try
            {
                return Ok(_checkAttendanceBll.DateDayOffA(id));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 特殊假日 特殊工作日 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DateSpecialDayOffB(int id)
        {
            try
            {
                return Ok(_checkAttendanceBll.DateSpecialDayOffB(id));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 上班 时间
        /// </summary>
        /// <param name="year"></param>
        /// <param name="name"></param>
        /// <param name="pumen"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowShangTime(int? year, string name, int? pumen)
        {
            try
            {
                return Ok(_checkAttendanceBll.ShowShangTime(year, name, pumen));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 下班 时间
        /// </summary>
        /// <param name="year"></param>
        /// <param name="name"></param>
        /// <param name="pumen"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowXiaTime(int? year, string name, int? pumen)
        {
            try
            {
                return Ok(_checkAttendanceBll.ShowXiaTime(year, name, pumen));
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 年假显示
        /// </summary>
        /// <param name="bum"></param>
        /// <param name="yearj"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowAnnual(int? bum, int? yearj)
        {
            try
            {
                return Ok(_checkAttendanceBll.ShowAnnual(bum, yearj));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 年假设置 
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult HolidayTime(List<AnnualLeave> ids)
        {
            try
            {
                return Ok(_checkAttendanceBll.HolidayTime(ids));
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        ///  导入 上传 Excel 特殊假日
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Uploading()
        {
            try
            {
                var excel = this.HttpContext.Request.Form.Files[0];
                var stream = new MemoryStream();
                excel.CopyTo(stream);
                var list = stream.Query<SpecialDayOffTable>().ToList();
                return Ok(_checkAttendanceBll.Uploading(list));
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
